import { Module } from "vuex";
import { IRootState } from "../types";
import { ITodoListState } from "./types";
import ITask from "@/pages/todolist/types/ITask";
import ITaskData from "@/pages/todolist/types/ITaskData";
import { defineStore } from "pinia";

const TodolistModule: Module<ITodoListState, IRootState> = {
  namespaced: true,
  state(){
    return {
      taskData: {
        completedTaskData: [],
        underwayTaskData: []
      }
    }
  },
  getters: {},
  mutations: {
    /**
     * 生成任务数据
     * @param state
     * @param payload
     */
    generateTaskData(state, payload){
      const { completedTaskData, underwayTaskData } = payload
      state.taskData.completedTaskData = completedTaskData
      state.taskData.underwayTaskData = underwayTaskData
    }
  },
  actions: {},
  modules: {}
}

export const usePiniaTodoListStore = defineStore({
  id: "todoList",
  state: () => {
    return {
      taskData: <ITaskData>{
        completedTaskData: <ITask[]>[] ,
        underwayTaskData: <ITask[]>[]
      }
    }
  },
  actions: {
    generateTaskData(taskData: ITaskData){
      const { completedTaskData, underwayTaskData } = taskData
      this.taskData.completedTaskData = completedTaskData
      this.taskData.underwayTaskData =underwayTaskData
    }
  }
})

export default TodolistModule

